package 竞赛.NO_451;

import java.util.Stack;

/**
 * 创建时间：2025-05-25 10:36
 */
public class Q2_移除相邻字符 {
    public String resultingString(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (!stack.isEmpty()) {
                if (Math.abs(c - stack.peek()) == 1 || Math.abs(c - stack.peek()) == 25) {
                    stack.pop();
                    continue;
                }
            }
            stack.push(c);
        }
        StringBuilder ans = new StringBuilder();
        for (char c : stack) {
            ans.append(c);
        }
        return ans.toString();
    }
}
